#include <dbg.h>

#include <cassert>
#include <numeric>

using namespace std;

class Solution {
public:
    vector<int> decrypt(vector<int>& code, int k) {
        int n = code.size();
        if (k == 0) {
            return vector<int>(n, k);
        }
        vector<int> res(n, 0);
        int right = k > 0 ? k + 1 : n;
        k = abs(k);
        int sum = reduce(code.begin() + right - k, code.begin() + right);
        for (int i = 0; i < n; i++) {
            res[i] = sum;
            sum += code[right % n] - code[(right - k) % n];
            ++right;
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> code1 = {5, 7, 1, 4};
    vector<int> code2 = {1, 2, 3, 4};
    vector<int> code3 = {2, 4, 9, 3};

    int k1 = 3;
    int k2 = 0;
    int k3 = -2;

    vector<int> res1 = {12, 10, 16, 13};
    vector<int> res2 = {0, 0, 0, 0};
    vector<int> res3 = {12, 5, 6, 13};

    assert(s.decrypt(code1, k1) == res1);
    assert(s.decrypt(code2, k2) == res2);
    assert(s.decrypt(code3, k3) == res3);

    return 0;
}